// vim:ft=javascript
//
// Copyright (c) 2026 - 2024 Gregor Kralik <g.kralik+php-sapnwrfc (at) gmail.com>
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
//
// Authors: Martin Keckeis <martin.keckeis1 (at) gmail.com>
//          Gregor Kralik <g.kralik+php-sapnwrfc (at) gmail.com>

ARG_WITH("sapnwrfc", "SAP NW RFC support", "no");

if (PHP_SAPNWRFC != "no") {

    var sdk_include_search_paths = [
        "C:\\nwrfcsdk\\include",
        "C:\\nwrfcsdk_750\\include",
        PHP_SAPNWRFC + "\\include"
    ];

	var sdk_lib_search_paths = [
        "C:\\nwrfcsdk\\lib",
        "C:\\nwrfcsdk_750\\lib",
        PHP_SAPNWRFC + "\\lib"
    ];

    if (
        CHECK_HEADER_ADD_INCLUDE("sapnwrfc.h", "CFLAGS_SAPNWRFC", sdk_include_search_paths.join(";")) &&
        CHECK_LIB("libsapucum.lib", "sapnwrfc", sdk_lib_search_paths.join(";")) &&
        CHECK_LIB("sapnwrfc.lib", "sapnwrfc", sdk_lib_search_paths.join(";"))
    ) {
        // all source files from the extension
        EXTENSION("sapnwrfc", "exceptions.c rfc_parameters.c sapnwrfc.c string_helper.c", PHP_SAPNWRFC_SHARED);

        // all header files from the extension
        PHP_INSTALL_HEADERS("ext/sapnwrfc", "exceptions.h php_sapnwrfc.h rfc_parameters.h string_helper.h");

        // set up CFLAGS
        var CFLAGS_SAPNWRFC = "-DSAPonNT -D_CRT_NON_CONFORMING_SWPRINTFS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_AFXDLL -DWIN32"
            + " -D_WIN32_WINNT=0x0502 -DWIN64 -D_AMD64_ -DNDEBUG -DSAPwithUNICODE -DUNICODE -D_UNICODE -DSAPwithTHREADS"
            + " -EHs -Gy -J -MD -nologo -W3 -Z7 -D_ATL_ALLOW_CHAR_UNSIGNED -GL -O2 -Oy- /we4552 /we4700 /we4789";
        ADD_FLAG("CFLAGS_SAPNWRFC", CFLAGS_SAPNWRFC)

        // skip  -MACHINE:amd64
        var LDFLAGS_SAPNWRFC = "-NXCOMPAT -STACK:0x2000000 -SWAPRUN:NET -DEBUG -OPT:REF"
            + " -DEBUGTYPE:CV,FIXUP -nologo -LTCG";
		ADD_FLAG("LDFLAGS_SAPNWRFC", LDFLAGS_SAPNWRFC);
    }

}
